
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Inspection;
import cn.edu.scau.cmi.hombio.domain.PigHouse;
import cn.edu.scau.cmi.hombio.domain.PigHouseType;
import cn.edu.scau.cmi.hombio.domain.Pigsty;
import cn.edu.scau.cmi.hombio.domain.TaskPighouse;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class PigHouseServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected PigHouseService service;

	/**
	 * Instantiates a new PigHouseServiceTest.
	 *
	 */
	public PigHouseServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Save an existing PigHouseType entity
	* 
	 */
	@Test
	public void savePigHousePigHouseType() {
		// TODO: JUnit - Populate test inputs for operation: savePigHousePigHouseType 
		Integer id = 0;
		PigHouseType related_pighousetype = new cn.edu.scau.cmi.hombio.domain.PigHouseType();
		PigHouse response = null;
		response = service.savePigHousePigHouseType(id, related_pighousetype);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigHousePigHouseType
	}

	/**
	 * Operation Unit Test
	* Delete an existing PigHouse entity
	* 
	 */
	@Test
	public void deletePigHouse() {
		// TODO: JUnit - Populate test inputs for operation: deletePigHouse 
		PigHouse pighouse = new cn.edu.scau.cmi.hombio.domain.PigHouse();
		service.deletePigHouse(pighouse);
	}

	/**
	 * Operation Unit Test
	* Delete an existing PigHouseType entity
	* 
	 */
	@Test
	public void deletePigHousePigHouseType() {
		// TODO: JUnit - Populate test inputs for operation: deletePigHousePigHouseType 
		Integer pighouse_id = 0;
		Integer related_pighousetype_id = 0;
		PigHouse response = null;
		response = service.deletePigHousePigHouseType(pighouse_id, related_pighousetype_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigHousePigHouseType
	}

	/**
	 * Operation Unit Test
	* Delete an existing TaskPighouse entity
	* 
	 */
	@Test
	public void deletePigHouseTaskPighouses() {
		// TODO: JUnit - Populate test inputs for operation: deletePigHouseTaskPighouses 
		Integer pighouse_id_1 = 0;
		Integer related_taskpighouses_id = 0;
		PigHouse response = null;
		response = service.deletePigHouseTaskPighouses(pighouse_id_1, related_taskpighouses_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigHouseTaskPighouses
	}

	/**
	 * Operation Unit Test
	* Delete an existing Inspection entity
	* 
	 */
	@Test
	public void deletePigHouseInspections() {
		// TODO: JUnit - Populate test inputs for operation: deletePigHouseInspections 
		Integer pighouse_id_2 = 0;
		Integer related_inspections_id = 0;
		PigHouse response = null;
		response = service.deletePigHouseInspections(pighouse_id_2, related_inspections_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigHouseInspections
	}

	/**
	 * Operation Unit Test
	* Save an existing Inspection entity
	* 
	 */
	@Test
	public void savePigHouseInspections() {
		// TODO: JUnit - Populate test inputs for operation: savePigHouseInspections 
		Integer id_1 = 0;
		Inspection related_inspections = new cn.edu.scau.cmi.hombio.domain.Inspection();
		PigHouse response = null;
		response = service.savePigHouseInspections(id_1, related_inspections);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigHouseInspections
	}

	/**
	 * Operation Unit Test
	* Save an existing Pigsty entity
	* 
	 */
	@Test
	public void savePigHousePigsties() {
		// TODO: JUnit - Populate test inputs for operation: savePigHousePigsties 
		Integer id_2 = 0;
		Pigsty related_pigsties = new cn.edu.scau.cmi.hombio.domain.Pigsty();
		PigHouse response = null;
		response = service.savePigHousePigsties(id_2, related_pigsties);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigHousePigsties
	}

	/**
	 * Operation Unit Test
	* Return all PigHouse entity
	* 
	 */
	@Test
	public void findAllPigHouses() {
		// TODO: JUnit - Populate test inputs for operation: findAllPigHouses 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<PigHouse> response = null;
		response = service.findAllPigHouses(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllPigHouses
	}

	/**
	 * Operation Unit Test
	* Return a count of all PigHouse entity
	* 
	 */
	@Test
	public void countPigHouses() {
		Integer response = null;
		response = service.countPigHouses();
		// TODO: JUnit - Add assertions to test outputs of operation: countPigHouses
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pigsty entity
	* 
	 */
	@Test
	public void deletePigHousePigsties() {
		// TODO: JUnit - Populate test inputs for operation: deletePigHousePigsties 
		Integer pighouse_id_3 = 0;
		Integer related_pigsties_id = 0;
		PigHouse response = null;
		response = service.deletePigHousePigsties(pighouse_id_3, related_pigsties_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigHousePigsties
	}

	/**
	 * Operation Unit Test
	* Save an existing PigHouse entity
	* 
	 */
	@Test
	public void savePigHouse() {
		// TODO: JUnit - Populate test inputs for operation: savePigHouse 
		PigHouse pighouse_1 = new cn.edu.scau.cmi.hombio.domain.PigHouse();
		service.savePigHouse(pighouse_1);
	}

	/**
	 * Operation Unit Test
	* Save an existing TaskPighouse entity
	* 
	 */
	@Test
	public void savePigHouseTaskPighouses() {
		// TODO: JUnit - Populate test inputs for operation: savePigHouseTaskPighouses 
		Integer id_3 = 0;
		TaskPighouse related_taskpighouses = new cn.edu.scau.cmi.hombio.domain.TaskPighouse();
		PigHouse response = null;
		response = service.savePigHouseTaskPighouses(id_3, related_taskpighouses);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigHouseTaskPighouses
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findPigHouseByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findPigHouseByPrimaryKey 
		Integer id_4 = 0;
		PigHouse response = null;
		response = service.findPigHouseByPrimaryKey(id_4);
		// TODO: JUnit - Add assertions to test outputs of operation: findPigHouseByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Load an existing PigHouse entity
	* 
	 */
	@Test
	public void loadPigHouses() {
		Set<PigHouse> response = null;
		response = service.loadPigHouses();
		// TODO: JUnit - Add assertions to test outputs of operation: loadPigHouses
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
